/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.unice.miage.projetjava.managers;

import fr.unice.miage.projetjava.entities.*;
import fr.unice.miage.projetjava.*;
import java.util.Collection;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Olivier
 */
@Stateless
public class GestionnaireDeLigneDeCommandeBean implements GestionnaireDeLigneDeCommandeLocal {
    @PersistenceContext
    private EntityManager em;
    
    public LigneDeCommande newLigneDeCommande(Produit prod, int qteProd, float prixUnit, Commande commande)
    {
        LigneDeCommande ldc = new LigneDeCommande();
        ldc.setProd(prod);
        ldc.setQteProd(qteProd);
        ldc.setPrixUnit(prixUnit);
        ldc.setCommande(commande);
        em.persist(ldc);
        return ldc;
    }

    public void deleteLigneDeCommande(int id)
    {
        LigneDeCommande ldc = em.find(LigneDeCommande.class, id);
        em.remove(ldc);
    }

    public Collection<LigneDeCommande> listeDeLigneDeCommande(Commande commande)
    {
        //trouver requete SQL avec un where
        Query query = em.createQuery("SELECT l FROM LigneDeCommande l WHERE l.Commande='"+commande+"'");
        return query.getResultList();
    }

    public void persist(Object object) {
        em.persist(object);
    }
    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method" or "Web Service > Add Operation")
 
}
